pkgname=igt
pkgver=git
pkgrel=1
arch=('i386' 'x86_64')
url="https://gitlab.freedesktop.org/drm/igt-gpu-tools"
license=('GPL')
makedepends_debian_11=(libunwind-dev libgsl-dev libasound2-dev libxmlrpc-core-c3-dev libjson-c-dev libcurl4-openssl-dev python3-docutils valgrind peg autoconf automake xutils-dev libtool make pkg-config cmake python3 python3-dev python3-libvirt python3-pip libc-bin libc6-dbg libc6 libc6-dev libdrm2 libdrm-dev libpciaccess-dev libkmod-dev libprocps-dev libelf-dev libdw1 libdw-dev libpixman-1-dev libcairo2-dev libudev-dev)
source=("https://gitlab.freedesktop.org/drm/igt-gpu-tools.git")
sha256sums=('SKIP')

build()
{
    if [ $os == "centos" ]; then
        pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple scikit-build
        wget https://cmake.org/files/v3.17/cmake-3.17.0.tar.gz
        tar -zvxf cmake-3.17.0.tar.gz
        cd cmake-3.17.0/ && ./bootstrap
        gmake
        gmake install
    fi
	python3 -m pip install meson
	python3 -m pip install ninja
	cd $srcdir/igt-gpu-tools
    if [ $os == "centos" ]; then
        sed -i '39a #include <linux/memfd.h>' tests/i915/gem_userptr_blits.c
    fi
	meson build && ninja -C build
}

split_tests()
{
	cd $srcdir/igt-gpu-tools
	# standalone test
	for test in $(cat $LKP_SRC/programs/${pkgname}/addon/tests/standalone | grep -v '^#')
	do
		echo $test > ./$test
	done

	standalone_tests=`paste -sd '|' <(cat $LKP_SRC/programs/${pkgname}/addon/tests/standalone | grep -v '^#')`
	sed -n '2p' build/tests/test-list.txt | tr " " "\n" | grep -v amdgpu | grep -vE "$standalone_tests" | sort > all-tests

	$LKP_SRC/tools/split-tests all-tests 25 group-
}

package()
{
	split_tests || return

	benchmark_path="${pkgdir}/lkp/benchmarks/${pkgname}"
	mkdir -p $benchmark_path
	cp -af "${srcdir}/igt-gpu-tools/"* $benchmark_path

	cp -af $LKP_SRC/programs/${pkgname}/exclude $benchmark_path
}
